home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_203 / gurusguide / intrmon.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  162 lines

  1. /************************************************************************
  2. **********                                                     **********
  3. **********          I N T E R R U P T   M O N I T O R          **********
  4. **********          ---------------------------------          **********
  5. **********                                                     **********
  6. **********        Copyright (C) 1988 Sassenrath Research       **********
  7. **********                All Rights Reserved.                 **********
  8. **********                                                     **********
  9. **********    Example from the "Guru's Guide, Meditation #1"   **********
  10. **********                                                     **********
  11. *************************************************************************
  12. **                                                                     **
  13. **                            - NOTICE -                               **
  14. **                                                                     **
  15. **  The "Guru's Guide, Meditation #1" contains detailed information    **
  16. **  about Amiga interrupts as well as a complete discussion of this    **
  17. **  and other examples.  Meditation #1 and all of its examples were    **
  18. **  written by Carl Sassenrath, the architect of Amiga's multitasking  **
  19. **  operating system.  Copies of the "Guru's Guide" may be obtained    **
  20. **  from:                                                              **
  21. **           GURU'S GUIDE, P.O. BOX 1510, UKIAH, CA 95482              **
  22. **                                                                     **
  23. **  Please include a check for $14.95, plus $1.50 shipping ($4.00 if   **
  24. **  outside North America).  CA residents add 6% sales tax.            **
  25. **                                                                     **
  26. **  This example may be used for any purposes, commercial, personal,   **
  27. **  public, and private, so long as ALL of the above text, copyright,  **
  28. **  mailing address, and this notice are retained in their entirety.   **
  29. **                                                                     **
  30. **  THIS EXAMPLE IS PROVIDED WITHOUT WARRANTY OF ANY KIND.             **
  31. **                                                                     **
  32. ************************************************************************/
  33.  
  34. /*
  35. **  IMPORTANT WARNING:
  36. **
  37. **  This program DOES NOT protect against state changes while
  38. **  accessing system structures.  It may in some cases produce
  39. **  unreliable results.  This example was produced for demonstration
  40. **  and debugging purposes only, and it should be used with care.
  41. */
  42.  
  43.  
  44. /*
  45. **  COMPILATION NOTE:
  46. **
  47. **  Compiled under MANX AZTEC C 3.6A.  Use the +L compiler option
  48. **  and the "c32" library.
  49. */
  50.  
  51.  
  52. #include <exec/exec.h>
  53. #include <exec/execbase.h>
  54. #include <hardware/custom.h>
  55.  
  56. #define    REG        register
  57. #define    FIRST(n)    (struct Interrupt *)((n)->lh_Head)
  58. #define    EMPTY(n)    ((n)->lh_Head == &n->lh_Tail)
  59. #define    NEXTINT(i)    (struct Interrupt *)((i)->is_Node.ln_Succ)
  60. #define    LAST(i)        (((i)->is_Node.ln_Succ)->ln_Succ == 0)
  61.  
  62.  
  63. struct ExecBase *EB;
  64.  
  65.  
  66. char *IntrName[] =
  67. {
  68.     "TBE",        "DISKBLK",    "SOFTINT",    "PORTS",
  69.     "COPER",    "VERTB",    "BLIT",        "AUD0",
  70.     "AUD1",        "AUD2",        "AUD3",        "RBF",    
  71.     "DSKSYNC",    "EXTER",    "INTEN",    "NMI"
  72. };
  73.  
  74.  
  75. char IntrPri[] = {1,1,1,2,3,3,3,4,4,4,4,5,5,6,6,7};
  76.  
  77.  
  78. main()
  79. {
  80.     extern VOID *OpenLibrary();
  81.  
  82.     puts("Guru's Guide Interrupt Table Printer\n");
  83.  
  84.     EB = OpenLibrary("exec.library", 0);
  85.     if (EB == NULL) exit(100);
  86.  
  87.     PrintAllIntr();
  88. }
  89.  
  90.  
  91. char *GetNodeName(node)
  92.     REG struct Node *node;
  93. {
  94.     if (node == NULL) return "";
  95.  
  96.     if (node->ln_Name == NULL) return "(missing)";
  97.     else return node->ln_Name;
  98. }
  99.  
  100.  
  101. int GetNodePri(node)
  102.     struct Node *node;
  103. {
  104.     if (node == NULL) return 0;
  105.  
  106.     return node->ln_Pri;
  107. }
  108.  
  109.  
  110. PrintAllIntr()
  111. {
  112.     REG int i;
  113.     REG struct IntVector *iv = &EB->IntVects[0];
  114.     APTR sc = (APTR) EB->IntVects[3].iv_Code;
  115.  
  116.     puts("IV E INTR    P S   CODE     DATA   NPR NAME");
  117.     puts("-- - ------- - - -------- -------- --- -----------------");
  118.  
  119.     for (i = 0; i < 16; i++, iv++)
  120.     {
  121.         printf("%2d %c %-7s %d ", i,
  122.             (custom.intenar & (1 << i)) ? '*' : ' ',
  123.             IntrName[i],
  124.             IntrPri[i]);
  125.  
  126.         if (iv->iv_Code == sc)
  127.         {
  128.             PrintServers(iv->iv_Data);
  129.         } else if (iv->iv_Code != 0)
  130.         {
  131.             printf("  %08lx %08lx     %s\n",
  132.                 iv->iv_Code,
  133.                 iv->iv_Data,
  134.                 GetNodeName(iv->iv_Node));
  135.         } else putchar('\n');
  136.     }
  137. }
  138.  
  139.  
  140. PrintServers(slist)
  141.     struct List *slist;
  142. {
  143.     REG struct Interrupt *s;
  144.  
  145.     if (EMPTY(slist))
  146.     {
  147.         puts("*");
  148.         return;
  149.     }
  150.  
  151.     for (s = FIRST(slist); NEXTINT(s) != 0; s = NEXTINT(s))
  152.     {
  153.         printf("* %08lx %08lx%4d %s\n",
  154.                 s->is_Code,
  155.                 s->is_Data,
  156.                 GetNodePri(s),
  157.                 GetNodeName(s));
  158.  
  159.         if (!LAST(s)) printf("               ");
  160.     }
  161. }
  162.